import numpy as np
import nibabel as nib
from ipywidgets import interact, interactive, IntSlider, ToggleButtons
import matplotlib.pyplot as plt
import seaborn as sns
#sns.set_style('darkgrid')

class NiiFile:
    def __init__(self, givenFilePath: str):
        self.__filePath = givenFilePath
        self.__data = self.__load()
        self.__height, self.__width, self.__depth =  self.__data.shape
        pass

    def __load(self):
        fileObj = nib.load(self.__filePath)
        data = fileObj.get_fdata()
        return data
    
    def showByHid(self, givenHid: int = 0, givenAux = None):
        if givenAux == None:
            plt.imshow(self.__data[givenHid, :, :], cmap='gray')
            plt.title(f'Height view ({givenHid}-th slice)')
            plt.show()
            return 
        if givenAux != None:
            givenAux.imshow(self.__data[givenHid, :, :], cmap='gray')
            givenAux.set_title(f'Height view ({givenHid}-th slice)')
            return
        pass

    def showByWid(self, givenWid: int = 0, givenAux = None):
        if givenAux == None:
            plt.imshow(self.__data[:, givenWid, :], cmap='gray')
            plt.title(f'Width view ({givenWid}-th slice)')
            plt.show()
            return 
        if givenAux != None:
            givenAux.imshow(self.__data[:, givenWid, :], cmap='gray')
            givenAux.set_title(f'Width view ({givenWid}-th slice)')
            return
        pass

    def showByDid(self, givenDid: int = 0, givenAux = None):
        if givenAux == None:
            plt.imshow(self.__data[:, :, givenDid], cmap='gray')
            plt.title(f'Depth view ({givenDid}-th slice)')
            plt.show()
            return 
        if givenAux != None:
            givenAux.imshow(self.__data[:, :, givenDid], cmap='gray')
            givenAux.set_title(f'Depth view ({givenDid}-th slice)')
            return
        pass

    def show(self, givenIdByX: int = 50, givenIdByY: int = 50, givenIdByZ: int = 50):
        fig, (auxX, auxY, auxZ) = plt.subplots(1,3,figsize=(12,6))
        self.showByHid(givenHid=givenIdByX, givenAux=auxX)
        self.showByWid(givenWid=givenIdByY,givenAux=auxY)
        self.showByDid(givenDid=givenIdByZ, givenAux=auxZ)
        plt.show()
        pass

    @property
    def data(self):
        return self.__data

    
    pass







class Test:
    def execute(self): 
        nf = NiiFile(givenFilePath='C:\\Users\\TFBOYS\\Documents\\data\\verse\\validation\\dataset-verse19validation\\derivatives\\sub-verse010\\sub-verse010_seg-vert_msk.nii.gz')
        nf.show(givenIdByX = 60, givenIdByY= 60, givenIdByZ = 60)
        pass
    pass


if __name__ == '__main__':
    Test().execute()




























